extends layout


block content
    input(type="file", name="", id="file")


    script.
        function UploadFile() {
            var fileObj = document.getElementById('file').files[0]
            var url = "http://localhost:3000/api/file_upload"

            var form = new FormData()
            form.append('file', fileObj)

            xhr = new XMLHttpRequest()
            xhr.open('post', url, true)
            xhr.onload = uploadComplete
            xhr.onerror = uploadFailed
            xhr.upload.onloadstart = function () {
                ot = new Date().getTime()
                onload = 0
            }
            xhr.send(form)
        }
        function uploadComplete (event) {
            console.log(event,event.target.responseText,'aabb')
            if(event.target.responseText === 'success') {
                console.log('success')
            }else{
                console.log('failed')
            }
        }
        function uploadFailed () {
            console.log('faild',"aaaa")
        }
        document.getElementById('file').addEventListener('change', UploadFile)